package com.singer.druid;


import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.singer.piping.JdbcPiping;
import javax.sql.DataSource;
import java.io.FileInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.util.Properties;

public class SingerIncrease implements JdbcPiping {
    /**
     * 对歌手进行添加！
     * @throws Exception
     */
    @Override
    public  void add(String name, int age, String sex,String song) throws Exception {
        Properties prop = new Properties();

        prop.load(new FileInputStream("src/druid.properties"));

        DataSource data = DruidDataSourceFactory.createDataSource(prop);

        Connection connection = data.getConnection();

        String sql = "insert into t_singer (name,age ,sex,song) values (?,?,?,?);";
        PreparedStatement ps = connection.prepareStatement(sql);

        ps.setString(1, name);
        ps.setInt(2, age);
        ps.setString(3, sex);
        ps.setString(4, song);
        int cou = ps.executeUpdate();
        if (cou > 0) {
            System.out.println("插入数据成功!");
        }

        ps.close();
        connection.close();
    }

    /**
     * 对裁判进行添加！
     * @param name
     * @param age
     * @param sex
     * @throws Exception
     */
    @Override
    public void add1(String name, int age, String sex) throws Exception {
        Properties prop = new Properties();

        prop.load(new FileInputStream("src/druid.properties"));

        DataSource data = DruidDataSourceFactory.createDataSource(prop);

        Connection connection = data.getConnection();

        String sql = "insert into t_judge (name,age ,sex) values (?,?,?);";
        PreparedStatement ps = connection.prepareStatement(sql);

        ps.setString(1, name);
        ps.setInt(2, age);
        ps.setString(3, sex);

        int cou = ps.executeUpdate();
        if (cou > 0) {
            System.out.println("插入数据成功!");
        }

        ps.close();
        connection.close();
    }
}

